window._MANAGERTJ = {

    _MAINLABEL:null,

    //当前左边菜单页码
    _LEFTPAGE:0,

    //左边菜单每页个数
    _LEFTPAGESIZE:8,

    //当前右边列表页码
    _RIGHTPAGE:0,

    //当前右边列表每页个数
    _RIGHTPAGESIZE:24,

    //图鉴类型下标
    _MAINTYPEINDEX:0,

    //当前tap选中
    _TAPTYPE:null,

    //tap按钮对应的左边菜单列表
    _TAPTYPEMAP:{},

    //当前左边菜单列表
    _TAPTYPEARR:null,

    //当前右边菜单选中
    _LEFTTYPE:null,

    //当前列表
    _GOODSARR:null,

    //图鉴类型列表
    _TJARR:[
        {name:'怪物图鉴',type:'boss',tab:['all','boss','ftype','level','maptype','xiuwei','race'],nodeType:'imgs'},
        {name:'职业图鉴',type:'job',tab:['all'],nodeType:'imgs'},
        {name:'修为图鉴',type:'xw',tab:['all'],nodeType:'imgs'},
        {name:'主动技能图鉴',type:'skill',tab:['all','xiuwei','status','ftype','skilltype','qua'],nodeType:'imgs'},
        {name:'被动技能图鉴',type:'skillbd',tab:['all','xiuwei','fsx','qua'],nodeType:'imgs'},
        {name:'装备图鉴',type:'equip',tab:['all','xiuwei','fsx','equipment','qua'],nodeType:'imgs'},
        {name:'道具图鉴',type:'item',tab:['all','qua','itemtype'],nodeType:'imgs'},
        {name:'副属性图鉴',type:'fsx',tab:['all'],nodeType:'words'},
        {name:'状态图鉴',type:'status',tab:['all','ftype','statustype'],nodeType:'words'},
    ],

    getTotalPer:function(){

        var nmb=0;
        var total=0;
        for(var i=0;i<_MANAGERTJ._TJARR.length;i++){

            var type = _MANAGERTJ._TJARR[i].type;
            var perObj=_MANAGERTJ.getPerOfType(type);
            nmb+=perObj.nmb;
            total+=perObj.total;
        }

        return {nmb:nmb,total:total};
    },

    getPerOfType:function(type){
        var nmb=0;
        var total=0;

        if(type=="boss"){
            for(var key in _NPC){
                if(_GAMEDATAHELPER.hasNpcTj(key)){
                    nmb++;
                }
                total++;
            }
        }else if(type=="job"){
            for(var key in _JOB){
                if(_GAMEDATAHELPER.hasNpcTj(key)){
                    nmb++;
                }
                total++;
            }
        }else if(type=="xw"){
            for(var key in _XW){
                if(_GAMEDATAHELPER.hasNpcTj(_XW[key].label)){
                    nmb++;
                }
                total++;
            }
        }else if(type=="skill"){
            for(var key in _SKILL){
                if(_GAMEDATAHELPER.hasNpcTj(key)){
                    nmb++;
                }
                total++;
            }
        }else if(type=="skillbd"){
            for(var key in _SKILLBD){
                if(_GAMEDATAHELPER.hasNpcTj(key)){
                    nmb++;
                }
                total++;
            }
        }else if(type=="equip"){
            for(var key in _EQUIP){
                if(_GAMEDATAHELPER.hasNpcTj(key)){
                    nmb++;
                }
                total++;
            }
        }else if(type=="item"){
            for(var key in _FIGHTITEM){
                if(_GAMEDATAHELPER.hasNpcTj(key)){
                    nmb++;
                }
                total++;
            }
    
        }else if(type=="fsx"){
            for(var key in _DICT){
                if(_GAMEDATAHELPER.hasNpcTj(_DICT[key])){
                    nmb++;
                }
                total++;
            }
        }else if(type=="status"){
            for(var key in _STATUSCONFCHESS){
                if(_GAMEDATAHELPER.hasNpcTj(_STATUSCONFCHESS[key].name)){
                    nmb++;
                }
                total++;
            }
        }
        return {per:nmb/total,nmb:nmb,total:total};
    },

    getPerStrOfType:function(type){
        var perObj = _MANAGERTJ.getPerOfType(type);
        var per = perObj.per;
        var total = perObj.total;
        var nmb = 1;
        if(total>100){
            nmb=3;
        }else if(total>10){
            nmb=2;
        }
        return (per*100).toFixed(nmb)+"%";
    },

    isTjNpc:function(npcname){

        if(_TJNPC[npcname]){
            return true;
        }

        return false;
    },

    getTjInfo:function(tjnpcindex,tjmap){
        return "战士";
    },

    getNpcPf:function(tjnpcindex,tjmap){

        if(_NPCMAP[tjmap]&&_NPCMAP[tjmap].npc){
            for(var i=0;i<_NPCMAP[tjmap].npc.length;i++){
                var per = _NPCMAP[tjmap].npc[i].per;
                var npcname = _NPCMAP[tjmap].npc[i].npc;
                if(per[0]==0&&per[0]==100){
                    if(_NPC[npcname]&&_NPC[npcname].pf){
                        return _NPC[npcname].pf;
                    }
                }
            }
        }

        return "山贼";
    },

    showTjNpcTalk:function(npc){
        _GAMEDATAHELPER.signNpcTj(npc);
        _MANAGERTALK.showTalk(_MAP.node,{
            talk:[{face:'问号',name:npc,msg:_MANAGERTJ.getTjMsg(npc)}]
        },_MAP);

    },

    getTjMsg:function(npc){
        return _TJNPC[npc];
    },

    getJobQua:function(job){

        if(_JOB[job]&&(
            _JOB[job].level
            ||_JOB[job].level==0
        )){

            var qua = "C";
            if(_JOB[job].level==0){
                qua='D';
            }else if(_JOB[job].level==1){
                qua='C';
            }else if(_JOB[job].level==2){
                qua='B';
            }else if(_JOB[job].level==3){
                qua='A';
            }else if(_JOB[job].level==4){
                qua='S';
            }else if(_JOB[job].level==5){
                qua='SS';
            }

            return qua;
        }

        return null;
    },

    getMaxXwOfNpc:function(npcconf){
        if(npcconf){
            var xwobj = _RHM.getMaxXwObj(npcconf.npcxw);
            if(xwobj)
                return xwobj.xw;
        }
        return null;
    },

    //查询图鉴
    reSearchGoodsArr:function(){
        
        var mainTypeObj = _MANAGERTJ._TJARR[_MANAGERTJ._MAINTYPEINDEX];
        var mainType = mainTypeObj.type;
        var tap = _MANAGERTJ._TAPTYPE;
        var condition = _MANAGERTJ._LEFTTYPE;
        _MANAGERTJ._GOODSARR = [];

        if(mainType=="job"){//支持修为 副属性 装备

            for(var key in _JOB){
                if(!condition){
                    _MANAGERTJ._GOODSARR.push({type:mainType,value:key,config:_JOB[key]});
                }else if(tap=="xiuwei"){
                    if(_JOB[key].xw&&_JOB[key].xw[condition]){
                        _MANAGERTJ._GOODSARR.push({type:mainType,value:key,config:_JOB[key]});
                    }
                }else if(tap=="equipment"){
                    if(_JOB[key].equipType&&_CU.isContain(_JOB[key].equipType,condition)){
                        _MANAGERTJ._GOODSARR.push({type:mainType,value:key,config:_JOB[key]});
                    }
                }else if(tap=="qua"){

                    var jobqua = _MANAGERTJ.getJobQua(key);
                    if(jobqua==condition){
                        _MANAGERTJ._GOODSARR.push({type:mainType,value:key,config:_JOB[key]});
                    }

                }else if(tap=="fsx"){

                    var skillbdArr = _CROF.getSkillOfJob(key);

                    if(skillbdArr&&skillbdArr.length>0){
                        for(var k=0;k<skillbdArr.length;k++){

                            if(_SKILLBD[skillbdArr[k]]
                                &&_SKILLBD[skillbdArr[k]].attr
                                &&_SKILLBD[skillbdArr[k]].attr[condition]){

                                _MANAGERTJ._GOODSARR.push({type:mainType,value:key,config:_JOB[key]});
                                break;

                            }

                        }
                    }
                }
            }

        }else if(mainType=="skill"){//支持修为 状态

            for(var key in _SKILL){
                if(!condition){
                    _MANAGERTJ._GOODSARR.push({type:mainType,value:key,config:_SKILL[key]});
                }else if(tap=="xiuwei"){
                    if(_SKILL[key].xw&&_SKILL[key].xw[condition]){
                        _MANAGERTJ._GOODSARR.push({type:mainType,value:key,config:_SKILL[key]});
                    }
                }else if(tap=="status"){
                    if(_SKILL[key].status==condition||_SKILL[key].selfstatus==condition){
                        _MANAGERTJ._GOODSARR.push({type:mainType,value:key,config:_SKILL[key]});
                    }
                }else if(tap=="qua"){
                    if(_SKILL[key].qua==condition){
                        _MANAGERTJ._GOODSARR.push({type:mainType,value:key,config:_SKILL[key]});
                    }
                }else if(tap=="skilltype"){
                    if(_SKILL[key].skilltype==condition){
                        _MANAGERTJ._GOODSARR.push({type:mainType,value:key,config:_SKILL[key]});
                    }
                }else if(tap=="ftype"){
                    if(_SKILL[key].ftype==condition){
                        _MANAGERTJ._GOODSARR.push({type:mainType,value:key,config:_SKILL[key]});
                    }
                }
            }

        }else if(mainType=="skillbd"){//支持修为 副属性

            for(var key in _SKILLBD){
                if(!condition){
                    _MANAGERTJ._GOODSARR.push({type:mainType,value:key,config:_SKILLBD[key]});
                }else if(tap=="xiuwei"){
                    if(_SKILLBD[key].xw&&_SKILLBD[key].xw[condition]){
                        _MANAGERTJ._GOODSARR.push({type:mainType,value:key,config:_SKILLBD[key]});
                    }
                }else if(tap=="fsx"){
                    if(_SKILLBD[key].attr&&_SKILLBD[key].attr[condition]){
                        _MANAGERTJ._GOODSARR.push({type:mainType,value:key,config:_SKILLBD[key]});
                    }
                }else if(tap=="qua"){
                    if(_SKILLBD[key].qua==condition){
                        _MANAGERTJ._GOODSARR.push({type:mainType,value:key,config:_SKILLBD[key]});
                    }
                }
            }

        }else if(mainType=="equip"){//支持修为 副属性 装备

            for(var key in _EQUIP){
                if(!condition){
                    _MANAGERTJ._GOODSARR.push({type:mainType,value:key,config:_EQUIP[key]});
                }else if(tap=="xiuwei"){
                    if(_EQUIP[key].xw&&_EQUIP[key].xw[condition]){
                        _MANAGERTJ._GOODSARR.push({type:mainType,value:key,config:_EQUIP[key]});
                    }
                }else if(tap=="fsx"){
                    if(_EQUIP[key].attr&&_EQUIP[key].attr[condition]){
                        _MANAGERTJ._GOODSARR.push({type:mainType,value:key,config:_EQUIP[key]});
                    }
                }else if(tap=="equipment"){
                    if(_EQUIP[key].type&&_EQUIP[key].type==condition){
                        _MANAGERTJ._GOODSARR.push({type:mainType,value:key,config:_EQUIP[key]});
                    }
                }else if(tap=="qua"){
                    if(_EQUIP[key].qua==condition){
                        _MANAGERTJ._GOODSARR.push({type:mainType,value:key,config:_EQUIP[key]});
                    }
                }
            }

        }else if(mainType=="boss"){//流派搜索

            if(tap=="maptype"&&_NPCMAP[condition]){

                var npcarr = _NPCMAP[condition].npc;
                for(var i=0;i<npcarr.length;i++){
                    var npcobj = npcarr[i];
                    _MANAGERTJ._GOODSARR.push({type:mainType,value:npcobj.npc,config:_NPC[npcobj.npc]});

                }

            }else{

                for(var key in _NPC){
                    if(condition){
                        if(tap=="level"){
                            if(_NPC[key].level==condition){
                                _MANAGERTJ._GOODSARR.push({type:mainType,value:key,config:_NPC[key]});
                            }
                        }else if(tap=="ftype"){
                            if(_NPC[key].ftype==condition){
                                _MANAGERTJ._GOODSARR.push({type:mainType,value:key,config:_NPC[key]});
                            }
                        }else if(tap=="boss"){
                            if(_NPC[key].job==condition){
                                _MANAGERTJ._GOODSARR.push({type:mainType,value:key,config:_NPC[key]});
                            }
                        }else if(tap=="race"){
                            if(_NPC[key].race==condition){
                                _MANAGERTJ._GOODSARR.push({type:mainType,value:key,config:_NPC[key]});
                            }
                        }else if(tap=="xiuwei"){//取最高修为
                            if(_MANAGERTJ.getMaxXwOfNpc(_NPC[key])==condition){
                                _MANAGERTJ._GOODSARR.push({type:mainType,value:key,config:_NPC[key]});
                            }
                        }
                    }else{
                        _MANAGERTJ._GOODSARR.push({type:mainType,value:key,config:_NPC[key]});
                    }
                }
            }

        }else if(mainType=="fsx"){

            for(var key in _DICT){
                _MANAGERTJ._GOODSARR.push({type:mainType,value:_DICT[key],config:key});
            }

        }else if(mainType=="xw"){

            for(var key in _XW){
                _MANAGERTJ._GOODSARR.push({type:mainType,value:_XW[key].label,config:_XW[key]});
            }

        }else if(mainType=="item"){

            for(var key in _FIGHTITEM){
                if(condition){
                    if(tap=="qua"){
                        if(_FIGHTITEM[key].qua==condition){
                            _MANAGERTJ._GOODSARR.push({type:mainType,value:key,config:_FIGHTITEM[key]});
                        }
                    }else if(tap=="itemtype"){
                        if(condition&&condition[_FIGHTITEM[key].skilltype]){
                            _MANAGERTJ._GOODSARR.push({type:mainType,value:key,config:_FIGHTITEM[key]});
                        }
                    }
                }else{
                    _MANAGERTJ._GOODSARR.push({type:mainType,value:key,config:_FIGHTITEM[key]});
                }
            }

        }else if(mainType=="status"){

            for(var key in _STATUSCONFCHESS){
                if(condition){
                    if(tap=="statustype"){
                        if(
                            _STATUSCONFCHESS[key].label==condition
                            ||(
                                condition=="特殊"
                                &&(
                                    _STATUSCONFCHESS[key].label!="增益"
                                    &&_STATUSCONFCHESS[key].label!="减益"
                                )
                            )
                        ){
                            _MANAGERTJ._GOODSARR.push({type:mainType,value:_STATUSCONFCHESS[key].name,config:_STATUSCONFCHESS[key]});
                        }
                    }else if(tap=="ftype"){
                        if(_FTYPESTATUSDEFEND[condition][key]){
                            _MANAGERTJ._GOODSARR.push({type:mainType,value:_STATUSCONFCHESS[key].name,config:_STATUSCONFCHESS[key]});
                        }
                    }
                }else{
                    _MANAGERTJ._GOODSARR.push({type:mainType,value:_STATUSCONFCHESS[key].name,config:_STATUSCONFCHESS[key]});
                }
            }

        }

    },

    //刷新列表
    refreshGoods:function(){

        var mainlabelNode = _MANAGERTJ._MAINLABEL.getChildByName('mainLabel');
        var rightNode = mainlabelNode.getChildByName('right');
        var goodsPageNode = rightNode.getChildByName('page');
        var goods = rightNode.getChildByName('goods').getChildren();
        var temparr = _MANAGERTJ._GOODSARR;
        var startIndex = _MANAGERTJ._RIGHTPAGE*_MANAGERTJ._RIGHTPAGESIZE;
        var endIndex = startIndex+_MANAGERTJ._RIGHTPAGESIZE;
        var nodeIndex = 0;
        for(var i=startIndex;i<endIndex;i++){

            var goodNode = goods[nodeIndex];
            var infoObj = temparr[i];
            _MANAGERTJ.refreshGood(goodNode,infoObj);
            nodeIndex++;
        }

        goodsPageNode.getChildByName('label').getComponent(cc.Label).string = _MANAGERTJ._RIGHTPAGE+1;

    },

    //刷新单个图鉴
    refreshGood:function(node,info){

        if(info){
            var mainTypeObj = _MANAGERTJ._TJARR[_MANAGERTJ._MAINTYPEINDEX];
            var nodeType = mainTypeObj.nodeType;
            var mainType = mainTypeObj.type;
            var wordsnode = node.getChildByName('words');
            var imgnode = node.getChildByName('imgs');
            var titlenode = wordsnode.getChildByName('title');
            var nameNode = imgnode.getChildByName('name');
            var cellimgNode = imgnode.getChildByName('img');
            var starNode = imgnode.getChildByName('xinxin');
            var ftypeNode = imgnode.getChildByName('wuxin');
            var zhongNode = imgnode.getChildByName('zhong');
            var lvNode = imgnode.getChildByName('level');
            var jobNode = imgnode.getChildByName('job');

            wordsnode.active = false;
            imgnode.active = false;
            starNode.active = false;
            ftypeNode.active =false;
            lvNode.active = false;
            zhongNode.active = false;
            jobNode.active = false;

            node.getChildByName(nodeType).active = true;
            node.color = new cc.color("#161410");

            if(_GAMEDATAHELPER.hasNpcTj(info.value)){

                if(nodeType=="imgs"){
                    nameNode.getComponent(cc.Label).string = info.value;
                }else{
                    titlenode.getComponent(cc.Label).string = info.value;
                }
                if(mainType=="job"){

                    cellimgNode.getComponent(cc.Sprite).spriteFrame = _GRM.getFaceFrame(info.config.face);
                    node.color= new cc.color(info.config.color);
                
                }else if(mainType=="skill"){
        
                    cellimgNode.getComponent(cc.Sprite).spriteFrame = _GRM.getEquipFrame(info.config.img);
                    if(info.config.ftype&&_CS.ftype[info.config.ftype]){
                        ftypeNode.active = true;
                        ftypeNode.getChildByName('label').getComponent(cc.Label).string = info.config.ftype;
                        ftypeNode.color = new cc.color(_CS.ftype[info.config.ftype].color);
                    }
                    if(_SKILLHEPLER.isZhuanshu(info.value)){
                        starNode.active = true;
                    }
                    if(info.config.qua&&_CS.qua[info.config.qua]){
                        node.color= new cc.color(_CS.qua[info.config.qua].color);
                    }
                }else if(mainType=="skillbd"){
                    
                    cellimgNode.getComponent(cc.Sprite).spriteFrame = _GRM.getEquipFrame(info.config.img);
                    if(_SKILLHEPLER.isZhuanshu(info.value)){
                        starNode.active = true;
                    }
                    if(info.config.qua&&_CS.qua[info.config.qua]){
                        node.color= new cc.color(_CS.qua[info.config.qua].color);
                    }
                }else if(mainType=="equip"){
                    
                    cellimgNode.getComponent(cc.Sprite).spriteFrame = _GRM.getEquipFrame(info.config.img);
                    if(info.config.qua&&_CS.qua[info.config.qua]){
                        node.color= new cc.color(_CS.qua[info.config.qua].color);
                    }
        
                }else if(mainType=="boss"){


                    cellimgNode.getComponent(cc.Sprite).spriteFrame = _GRM.getFaceFrame(info.config.face);
                        if(info.config.ftype&&_CS.ftype[info.config.ftype]){
                            ftypeNode.active = true;
                            ftypeNode.getChildByName('label').getComponent(cc.Label).string = info.config.ftype;
                            ftypeNode.color = new cc.color(_CS.ftype[info.config.ftype].color);
                        }

                        var rolerace = info.config.race;
                        var rolejob = info.config.job;
                        jobNode.active = true;
                        jobNode.getChildByName('ftypeStr').getComponent(cc.Label).string = window._JOB[rolejob]?window._JOB[rolejob].sname:'?';
                        jobNode.color = new cc.color(window._JOB[rolejob].color);
                        
                        if(window._RACE[rolerace]){
                            zhongNode.getChildByName('ftypeStr').getComponent(cc.Label).string = window._RACE[rolerace].name;
                            zhongNode.color = new cc.color(window._RACE[rolerace].color);
                            zhongNode.active = true;
                        }else{
                            zhongNode.active = false;
                        }
                        
                        lvNode.active = true;
                        lvNode.getChildByName('ftypeStr').getComponent(cc.Label).string = info.config.level;
                        lvNode.color = new cc.color(window._CS.qua[info.config.level].color);
        
                }else if(mainType=="item"){
        
                    cellimgNode.getComponent(cc.Sprite).spriteFrame = _GRM.getEquipFrame(info.config.img);
                    if(info.config.qua&&_CS.qua[info.config.qua]){
                        node.color= new cc.color(_CS.qua[info.config.qua].color);
                    }
                }else if(mainType=="xw"){
                    cellimgNode.getComponent(cc.Sprite).spriteFrame = _GRM.getEquipFrame(info.config.img);
                    if(info.config.attr&&_CS.attrColor[info.config.attr]){
                        node.color= new cc.color(_CS.attrColor[info.config.attr]);
                    }
                }
            }else{

                cellimgNode.getComponent(cc.Sprite).spriteFrame = _GRM.getFaceFrame("问号");
                if(mainType=="boss"){
                    var level = info.config.level;
                    var race = _RACE[info.config.race].name;
                    if(!_MRMN.canMeet(info.config.name)){
                        nameNode.getComponent(cc.Label).string = race+level;
                        titlenode.getComponent(cc.Label).string = race+level;
                    }else{
                        nameNode.getComponent(cc.Label).string = "可遇到";
                        titlenode.getComponent(cc.Label).string = "可遇到";
                    }
                }else{
                    nameNode.getComponent(cc.Label).string = "???";
                    titlenode.getComponent(cc.Label).string = "???";
                }
                
            }
            node.active = true;
        }else{
            node.active = false;
        }

    },

    showTJ:function(){

        //完成新手任务
        //_TTCH.doCompleteTask('clickTj',null,true);

        var uiObj = _GRM.getNodeObj('tujian');
        var uiNode = uiObj.node;
        _MANAGERTJ._MAINLABEL = uiNode;

        if(uiObj.isnew){
            _MANAGERTJ.initButton();
        }
        _MANAGERTJ.refreshMainType();
        _MAP.node.addChild(uiNode);
    },

    initButton:function(){

        if(!_MANAGERTJ._MAINLABEL){
            return ;
        }

        var mainlabelNode = _MANAGERTJ._MAINLABEL.getChildByName('mainLabel');
        var rightNode = mainlabelNode.getChildByName('right');
        var leftNode = mainlabelNode.getChildByName('left');
        var maskNode = _MANAGERTJ._MAINLABEL.getChildByName('mask');

        maskNode.on(cc.Node.EventType.TOUCH_START, function(){
            _GRM.putNode(this);
        }, _MANAGERTJ._MAINLABEL);

        //主分类按钮
        var searchBtn = mainlabelNode.getChildByName('searchBtn');
        searchBtn.on(cc.Node.EventType.TOUCH_START, function(){
            //_TIPS.showMessage('切换图鉴');
            _MANAGERTJ.switchMainType();
        }, _MANAGERTJ._MAINLABEL);

        //小分类按钮
        var typsNodes = leftNode.getChildByName('list').getChildren();
        for(var i=0;i<typsNodes.length;i++){
            var tempNode = typsNodes[i];
            tempNode.nodeIndex = i;
            tempNode.on(cc.Node.EventType.TOUCH_START, function(){
                var leftarr = _MANAGERTJ._TAPTYPEARR;
                var realindex = _MANAGERTJ._LEFTPAGE*_MANAGERTJ._LEFTPAGESIZE+this.nodeIndex;
                var realtype = leftarr[realindex];
                _MANAGERTJ._LEFTTYPE = realtype.value;
                _MANAGERTJ._RIGHTPAGE=0;
                _MANAGERTJ.reSearchGoodsArr();
                _MANAGERTJ.refreshGoods();

                //_TIPS.showMessage('小分类:'+realtype.name+" "+realtype.value);
            }, tempNode);
        }

        //小分类分页按钮
        var typesPageNode = leftNode.getChildByName('page');
        var typesPageLeftBtn = typesPageNode.getChildByName('btnLeft');
        var typesPageRightBtn = typesPageNode.getChildByName('btnRight');
        typesPageLeftBtn.on(cc.Node.EventType.TOUCH_START, function(){
            //_TIPS.showMessage('小分类上一页');
            if(_MANAGERTJ._LEFTPAGE>0){
                _MANAGERTJ._LEFTPAGE--;
                _MANAGERTJ.refreshLeftType();
            }
        }, typesPageLeftBtn);
        typesPageRightBtn.on(cc.Node.EventType.TOUCH_START, function(){
            _MANAGERTJ._LEFTPAGE++;
            _MANAGERTJ.refreshLeftType();
        }, typesPageRightBtn);

        //大分类按钮
        var tabNode = rightNode.getChildByName('tab');
        var tabAllBtn = tabNode.getChildByName('all');
        var tabFsxBtn = tabNode.getChildByName('fsx');
        var tabXiuweiBtn = tabNode.getChildByName('xiuwei');
        var tabStatusBtn = tabNode.getChildByName('status');
        var tabBossBtn = tabNode.getChildByName('boss');
        var tabEquipmentBtn = tabNode.getChildByName('equipment');
        var tabmapBtn = tabNode.getChildByName('maptype');

        var quaBtn = tabNode.getChildByName('qua');
        var levelBtn = tabNode.getChildByName('level');
        var ftypeBtn = tabNode.getChildByName('ftype');
        var skilltypeBtn = tabNode.getChildByName('skilltype');
        var itemtypeBtn = tabNode.getChildByName('itemtype');
        var statustypeBtn = tabNode.getChildByName('statustype');
        var raceBtn = tabNode.getChildByName('race');


        tabmapBtn.on(cc.Node.EventType.TOUCH_START, function(){
            //_TIPS.showMessage('大分类:全部');
            _MANAGERTJ.selectByTap('maptype');
        }, tabmapBtn);

        raceBtn.on(cc.Node.EventType.TOUCH_START, function(){
            //_TIPS.showMessage('大分类:全部');
            _MANAGERTJ.selectByTap('race');
        }, tabmapBtn);

        tabAllBtn.on(cc.Node.EventType.TOUCH_START, function(){
            //_TIPS.showMessage('大分类:全部');
            _MANAGERTJ.selectByTap('all');
        }, tabAllBtn);
        tabFsxBtn.on(cc.Node.EventType.TOUCH_START, function(){
            //_TIPS.showMessage('大分类:副属性');
            _MANAGERTJ.selectByTap('fsx');
        }, tabFsxBtn);
        tabXiuweiBtn.on(cc.Node.EventType.TOUCH_START, function(){
            //_TIPS.showMessage('大分类:修为');
            _MANAGERTJ.selectByTap('xiuwei');
        }, tabXiuweiBtn);
        tabStatusBtn.on(cc.Node.EventType.TOUCH_START, function(){
            //_TIPS.showMessage('大分类:状态');
            _MANAGERTJ.selectByTap('status');
        }, tabStatusBtn);
        tabBossBtn.on(cc.Node.EventType.TOUCH_START, function(){
            //_TIPS.showMessage('大分类:流派');
            _MANAGERTJ.selectByTap('boss');
        }, tabBossBtn);
        tabEquipmentBtn.on(cc.Node.EventType.TOUCH_START, function(){
            //_TIPS.showMessage('大分类:装备类型');
            _MANAGERTJ.selectByTap('equipment');
        }, tabEquipmentBtn);

        quaBtn.on(cc.Node.EventType.TOUCH_START, function(){
            _MANAGERTJ.selectByTap('qua');
        }, quaBtn);
        levelBtn.on(cc.Node.EventType.TOUCH_START, function(){
            _MANAGERTJ.selectByTap('level');
        }, levelBtn);
        ftypeBtn.on(cc.Node.EventType.TOUCH_START, function(){
            _MANAGERTJ.selectByTap('ftype');
        }, ftypeBtn);
        skilltypeBtn.on(cc.Node.EventType.TOUCH_START, function(){
            _MANAGERTJ.selectByTap('skilltype');
        }, skilltypeBtn);
        itemtypeBtn.on(cc.Node.EventType.TOUCH_START, function(){
            _MANAGERTJ.selectByTap('itemtype');
        }, itemtypeBtn);
        statustypeBtn.on(cc.Node.EventType.TOUCH_START, function(){
            _MANAGERTJ.selectByTap('statustype');
        }, statustypeBtn);

        //列表
        var goods = rightNode.getChildByName('goods').getChildren();
        for(var i=0;i<goods.length;i++){
            var tempNode = goods[i];
            tempNode.nodeIndex = i;
            tempNode.on(cc.Node.EventType.TOUCH_START, function(){
                //_TIPS.showMessage('列表:'+this.nodeIndex);
                var arr = _MANAGERTJ._GOODSARR;
                var realindex = _MANAGERTJ._RIGHTPAGE*_MANAGERTJ._RIGHTPAGESIZE+this.nodeIndex;
                var realobj = arr[realindex];

                if(!_GAMEDATAHELPER.hasNpcTj(realobj.value)){
                    return ;
                }

                var mainTypeObj = _MANAGERTJ._TJARR[_MANAGERTJ._MAINTYPEINDEX];
                var mainType = mainTypeObj.type;
        
                if(mainType=="job"){

                    _MJOB.showJobDes({job:realobj.value});
        
                }else if(mainType=="skill"){

                    _MGD.showGoodsUi(_MAP.node,
                        _IOF.createObjByName(realobj.value),
                        {pos:_MGD._POSTUJ});
        
                }else if(mainType=="skillbd"){
                    
                    _MGD.showGoodsUi(_MAP.node,
                        _IOF.createObjByName(realobj.value),
                        {pos:_MGD._POSTUJ});

                }else if(mainType=="equip"){
        
                    _MGD.showGoodsUi(_MAP.node,
                        _IOF.createObjByName(realobj.value),
                        {pos:_MGD._POSTUJ});

                }else if(mainType=="boss"){

                    _NPCDL.initUi(_MAP.node,{sence:_STYPE._FIGHTSENCE,
                        roleArr:_MANAGERTJ._GOODSARR,
                        roleIndex:realindex
                        });
        
                }else if(mainType=="fsx"){
        
                    for(var i=0;i<window._HELPERDOC.length;i++){
                        if(realobj.value==window._HELPERDOC[i][0]){
                            _TIPS.showMessage(realobj.value+":"+_HELPERDOC[i][1]);
                            break;
                        }
                    }

                }else if(mainType=="item"){
        
                    _MGD.showGoodsUi(_MAP.node,
                        _IOF.createObjByName(realobj.value),
                        {pos:_MGD._POSTUJ});

                }else if(mainType=="status"){                    
                    _TIPS.showMessage(realobj.config.name+":"+realobj.config.des);
                }else if(mainType=="xw"){                    
                    _TIPS.showMessage(XWH.showXwDes(realobj.value));
                }

            }, tempNode);
        }

        //列表分页
        var goodsPageNode = rightNode.getChildByName('page');
        var goodsPageLeftBtn = goodsPageNode.getChildByName('btnLeft');
        var goodsPageRightBtn = goodsPageNode.getChildByName('btnRight');
        var goodsPageTailBtn = goodsPageNode.getChildByName('tail');
        var goodsPageFirstBtn = goodsPageNode.getChildByName('first');
        goodsPageLeftBtn.on(cc.Node.EventType.TOUCH_START, function(){
            //_TIPS.showMessage('列表上一页');
            if(_MANAGERTJ._RIGHTPAGE>0){
                _MANAGERTJ._RIGHTPAGE--;
                _MANAGERTJ.refreshGoods();
            }
        }, goodsPageLeftBtn);
        goodsPageRightBtn.on(cc.Node.EventType.TOUCH_START, function(){
            //_TIPS.showMessage('列表下一页');
            _MANAGERTJ._RIGHTPAGE++;
            _MANAGERTJ.refreshGoods();
        }, goodsPageRightBtn);
        goodsPageTailBtn.on(cc.Node.EventType.TOUCH_START, function(){
            //_TIPS.showMessage('列表尾页');
            var lastpage = Math.floor(_MANAGERTJ._GOODSARR.length/_MANAGERTJ._RIGHTPAGESIZE)
            if(_MANAGERTJ._RIGHTPAGE!=lastpage){
                _MANAGERTJ._RIGHTPAGE=lastpage;
                _MANAGERTJ.refreshGoods();
            }
        }, goodsPageTailBtn);
        goodsPageFirstBtn.on(cc.Node.EventType.TOUCH_START, function(){
            //_TIPS.showMessage('列表首页');
            if(_MANAGERTJ._RIGHTPAGE!=0){
                _MANAGERTJ._RIGHTPAGE=0;
                _MANAGERTJ.refreshGoods();
            }
        }, goodsPageFirstBtn);

    },

    //切换图鉴
    switchMainType:function(){

        _MANAGERTJ._MAINTYPEINDEX++;
        if(_MANAGERTJ._MAINTYPEINDEX>=_MANAGERTJ._TJARR.length){
            _MANAGERTJ._MAINTYPEINDEX=0;
        }

        _MANAGERTJ.refreshMainType();
        

    },

    //刷新图鉴
    refreshMainType:function(){

        var tjobj = _MANAGERTJ._TJARR[_MANAGERTJ._MAINTYPEINDEX];
        var realtype = tjobj.type;
        var perstr = _MANAGERTJ.getPerStrOfType(realtype);
        _MANAGERTJ._TAPTYPE = tjobj.tab[0];
        _MANAGERTJ._LEFTTYPE = null;
        var mainlabelNode = _MANAGERTJ._MAINLABEL.getChildByName('mainLabel');
        var searchBtn = mainlabelNode.getChildByName('searchBtn');
        searchBtn.getChildByName('Background')
        .getChildByName('Label').getComponent(cc.Label).string = tjobj.name+"("+perstr+")";

        _MANAGERTJ.selectByTap(_MANAGERTJ._TAPTYPE);

    },

    //选中tap
    selectByTap:function(tap){

        _MANAGERTJ._TAPTYPE = tap;
        _MANAGERTJ._LEFTTYPE=null;
        _MANAGERTJ.refreshTap();
        _MANAGERTJ._TAPTYPEARR = _MANAGERTJ.getTapTypeArr();
        _MANAGERTJ._LEFTPAGE=0;
        _MANAGERTJ._RIGHTPAGE=0;
        _MANAGERTJ.refreshLeftType();
        _MANAGERTJ.reSearchGoodsArr();
        _MANAGERTJ.refreshGoods();
    },

    //刷新tap按钮
    refreshTap:function(){
        var tjobj = _MANAGERTJ._TJARR[_MANAGERTJ._MAINTYPEINDEX];
        var tabArr = tjobj.tab;
        var mainlabelNode = _MANAGERTJ._MAINLABEL.getChildByName('mainLabel');
        var rightNode = mainlabelNode.getChildByName('right');
        var tabNode = rightNode.getChildByName('tab');
        for(var i=0;i<tabNode.getChildren().length;i++){
            tabNode.getChildren()[i].active = false;
        }

        for(var i=0;i<tabArr.length;i++){

            if(tabArr[i]==_MANAGERTJ._TAPTYPE){
                tabNode.getChildByName(tabArr[i]+"1").active = true;
            }else{
                tabNode.getChildByName(tabArr[i]).active = true;
            }

        }

    },

    //刷新左边菜单
    refreshLeftType:function(){

        var mainlabelNode = _MANAGERTJ._MAINLABEL.getChildByName('mainLabel');
        var leftNode = mainlabelNode.getChildByName('left');
        var typsNodes = leftNode.getChildByName('list').getChildren();
        var typesPageNode = leftNode.getChildByName('page');

        var leftarr = _MANAGERTJ._TAPTYPEARR;
        var startindex = _MANAGERTJ._LEFTPAGE*_MANAGERTJ._LEFTPAGESIZE;
        var endIndex = startindex+_MANAGERTJ._LEFTPAGESIZE;
        var nodeIndex = 0;
        for(var i=startindex;i<endIndex;i++){

            if(leftarr[i]){
                typsNodes[nodeIndex].active = true;
                typsNodes[nodeIndex].getChildByName('Background')
                .getChildByName('Label').getComponent(cc.Label).string = leftarr[i].name;
            }else{
                typsNodes[nodeIndex].active = false;
            }
            nodeIndex++;
        }

        typesPageNode.getChildByName('label').getComponent(cc.Label).string = (_MANAGERTJ._LEFTPAGE+1);
    },

    //获取tap分类列表
    getTapTypeArr:function(){

        var currentTap = _MANAGERTJ._TAPTYPE;
        if(!_MANAGERTJ._TAPTYPEMAP[currentTap]){
            _MANAGERTJ._TAPTYPEMAP[currentTap]=[];

            if(currentTap=="status"){

                for(var key in _STATUSCONFCHESS){

                    _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:_STATUSCONFCHESS[key].name,value:key});

                }

            }else if(currentTap=="race"){

                for(var key in _RACE){
                    _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:_RACE[key].name,value:key});
                }

            }else if(currentTap=="fsx"){

                for(var key in _DICT){

                    _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:_DICT[key],value:key});

                }

            }else if(currentTap=="xiuwei"){

                for(var key in _XW){

                    _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:_XW[key].label,value:key});

                }

            }else if(currentTap=="equipment"){

                _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:'刀',value:'刀'});
                _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:'剑',value:'剑'});
                _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:'弓',value:'弓'});
                _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:'枪',value:'枪'});
                _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:'扇',value:'扇'});
                _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:'符',value:'符'});
                _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:'法宝',value:'法宝'});
                _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:'坐骑',value:'坐骑'});
                _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:'布甲',value:'布甲'});
                _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:'重甲',value:'重甲'});
                _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:'皮甲',value:'皮甲'});

            }else if(currentTap=="boss"){

                for(var key in _JOB){

                    _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:key,value:key});

                }

            }else if(currentTap=="qua"){

                _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:'D',value:'D'});
                _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:'C',value:'C'});
                _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:'B',value:'B'});
                _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:'A',value:'A'});
                _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:'S',value:'S'});
                _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:'SS',value:'SS'});

            }else if(currentTap=="level"){

                _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:'D',value:'D'});
                _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:'C',value:'C'});
                _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:'B',value:'B'});
                _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:'A',value:'A'});
                _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:'S',value:'S'});
                _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:'SS',value:'SS'});

            }else if(currentTap=="ftype"){

                _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:'金',value:'金'});
                _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:'木',value:'木'});
                _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:'水',value:'水'});
                _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:'火',value:'火'});
                _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:'土',value:'土'});

            }else if(currentTap=="skilltype"){

                for(var key in _SKILLTYPE){
                    _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:_SKILLTYPE[key],value:key});
                }

            }else if(currentTap=="itemtype"){

                var tempmap = {};
                for(var key in _FIGHTITEMTYPE){
                    //_MANAGERTJ._TAPTYPEMAP[currentTap].push({name:_FIGHTITEMTYPE[key],value:key});
                    if(!tempmap[_FIGHTITEMTYPE[key]]){
                        tempmap[_FIGHTITEMTYPE[key]]={};
                    }
                    tempmap[_FIGHTITEMTYPE[key]][key]=1;
                }

                for(var key in tempmap){
                    _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:key,value:tempmap[key]});
                }

            }else if(currentTap=="statustype"){
                _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:'增益',value:'增益'});
                _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:'减益',value:'减益'});
                _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:'特殊',value:'特殊'});
            }else if(currentTap=="maptype"){

                for(var key in _NPCMAP){

                    _MANAGERTJ._TAPTYPEMAP[currentTap].push({name:key,value:key});

                }

            }

        }
        return _MANAGERTJ._TAPTYPEMAP[currentTap];
    },

}